<div class="bjui-pageHeader">
    <table class="table table-bordered table-hover table-striped table-top">
        <!-- 商品名称 	商品货号 	数量(2) 	零售单价 	颜色规格  -->
        <tr>
            <th>商品名称</th>
            <th>商品货号</th>
            <th>数量</th>
            <th>零售单价</th>
            <th>颜色规格</th>
        </tr>
        <tr>
            <td>{$orderGoodsArr.goods_name}</td>
            <td>{$orderGoodsArr.goods_sn}</td>
            <td>{$orderGoodsArr.goods_number}</td>
            <td>{$orderGoodsArr.goods_price}</td>
            <td>{$orderGoodsArr.goods_color},{$orderGoodsArr.goods_size}</td>
        </tr>
    </table>
    <form id="pagerForm" data-toggle="ajaxsearch" action="{:U('ajaxBarCodeSearch')}" method="post">
        <!-- <input type="hidden" name="inputName" value="{:I('request.inputName')}"> -->
        <input type="hidden" name="orderId" value="{:I('request.orderId')}">
        <input type="hidden" name="orderGoodsId" value="{:I('request.orderGoodsId')}">

        <div class="bjui-searchBar">
            <select name="key" data-toggle="selectpicker">
                <option value="name"
                <?php echo I("key")=="name" ? "selected='true'" : "";?>>名称</option>
                <option value="sn"
                <?php echo I("key")=="sn" ? "selected='true'" : "";?>>货号</option>
                <option value="bar_code"
                <?php echo I("key")=="bar_code" ? "selected='true'" : "";?>>条码</option>
            </select>
            <input type="text" value="{:I('goodsName')|I('value')}" name="value" size="30">
            <button type="submit" class="btn-default" data-icon="search">查询</button>
        </div>
    </form>
</div>
<div class="bjui-pageContent tableContent">
    <table class="table table-bordered table-hover table-striped table-top">
        <thead>
            <tr>
                <th>商品名称</th>
                <th data-order-field="color_id">颜色</th>
                <th data-order-field="spec_id">规格</th>
                <th data-order-field="bar_code">条码</th>
                <th>数量</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach($list as $arr):?>
            <tr>
                <td>{$arr.goods_name}</td>
                <td>{$arr.color_name}</td>
                <td>{$arr.spec_name}</td>
                <td>{$arr.bar_code}</td>
                <td>
                    <input type="text" data-step="1" data-max="{$arr['number']-$arr['presell_number']}" data-min="1" data-toggle="spinner" size="5" value="{$orderGoodsArr.goods_number}">
                    <code style="color:blue;">{$arr.number}</code>|<code>{$arr.presell_number}</code>
                </td>
                <td>
                    <!-- <a href="javascript:;" data-toggle="lookupback" data-args='<?php echo json_encode(array($_REQUEST['inputName'].'[goods_id]'=>$arr['goods_id'],$_REQUEST['inputName'].'[bar_code]'=>$arr['bar_code'],));?>' class="btn btn-blue" title="选择本项" data-icon="check">选择</a> -->
                    <a class="btn btn-blue" title="选择本项" data-icon="check" onclick="javascript:chooseBarCode(this);">选择</a>
                </td>
                <input type="hidden" name="barCodeId" value="{$arr.id}">
                <input type="hidden" name="goodsId" value="{$arr.goods_id}">
            </tr>
            <?php endforeach;?>
        </tbody>
    </table>
</div>
<script>

    /**
     * [chooseBarCode 选择对应的条码商品]
     * @param  {[type]} obj [description]
     * @return {[type]}     [description]
     */
    function chooseBarCode(obj){
        var tableBarCode = $(obj).parent().parent();
        var options = {};
        options['url'] = "{:U('Order/addGoods')}";
        options['type'] = "POST";
        options['callback'] = "addGoodsCallBack";
        options['data'] = {};
        options['data']['order_id'] = "{:I('request.orderId')}";   // 订单id
        options['data']['order_goods_id'] = "{:I('request.orderGoodsId')}";   // order_goods表id
        options['data']['number'] = tableBarCode.find("input[type=text][data-toggle=spinner]").val();
        options['data']['bar_code_id'] = tableBarCode.find("input[type=hidden][name=barCodeId]").val();
        options['data']['goods_id'] = tableBarCode.find("input[type=hidden][name=goodsId]").val();
        if(options['data']['number']!='{$orderGoodsArr.goods_number}'){
            $(this).alertmsg('error', '商品数量不符合商品原有的指定数量');
            return;
        }
        $(obj).bjuiajax('doAjax', options);
    }


</script>